package com.appspot.didit.client.user;

import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.event.dom.client.HasKeyPressHandlers;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DecoratorPanel;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.HasText;
import com.google.gwt.user.client.ui.HasValue;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.PasswordTextBox;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

public class RegisterView extends Composite implements RegisterPresenter.View {
	
	public final Label usernameLabel;
	
	public final TextBox usernameTb;
	
	public final Label passwordLabel;

	public final PasswordTextBox passwordTb;
	
	public final Label passwordReLabel;
	
	public final PasswordTextBox passwordReTb;
	
	public final Label registerHint;
	
	public final Button checkAvailableButton;
	
	public final Button registerButton;
	
	public final Button registerResetButton;
	
    public RegisterView() {
    	VerticalPanel vp = new VerticalPanel();
    	registerHint = new Label();
    	registerHint.setStylePrimaryName("hints");
        usernameLabel = new Label("Gew\u00fcnschter Benutzername:");//Desired Login Name
        usernameTb = new TextBox();
        usernameTb.setWidth("250px");
        
        
        passwordLabel = new Label("Passwort w\u00e4hlen:");//Choose a password
        passwordTb = new PasswordTextBox();
        passwordTb.setWidth("250px");

        passwordReLabel = new Label("Passwort best\u00e4tigen:");//Re-enter password
        passwordReTb = new PasswordTextBox();
        passwordReTb.setWidth("250px");
        
        checkAvailableButton = new Button("Verf\u00fcgbarkeit pr\u00fcfen!");//Check Availability
        
        registerButton = new Button("Mein Konto einrichten");//Create an Account
        
        registerResetButton = new Button("Reset");
        
        FlexTable layout = new FlexTable();
        layout.setCellSpacing(10);

        // Add some standard form options
        //layout.setWidget(0, 0, registerHint);
        layout.setWidget(1, 0, usernameLabel);
        layout.setWidget(1, 1, usernameTb);
        layout.setWidget(2, 0, checkAvailableButton);
        layout.setWidget(3, 0, passwordLabel);
        layout.setWidget(3, 1, passwordTb);
        layout.setWidget(4, 0, passwordReLabel);
        layout.setWidget(4, 1, passwordReTb);
        
        layout.setWidget(5, 0, registerButton);
        layout.setWidget(5, 1, registerResetButton);
        vp.add(registerHint);
        vp.add(layout);
        initWidget(vp);
    }

    public Widget getWidget() {
            return this;
    }

    public void reset() {
    	registerHint.setText("");
    	usernameTb.setValue("");
    	
    	passwordTb.setValue("");
    	
    	passwordReTb.setValue("");
    }
    
	
	public HasClickHandlers getRegisterClickHandlers() {
		return registerButton;
	}
	
	public HasClickHandlers getRegisterResetClickHandlers() {
		return registerResetButton;
	}
	
	public HasClickHandlers getCheckAvailableClickHandlers() {
		return checkAvailableButton;
	}

	public HasValue<String> getUsername() {
		return usernameTb;
	}

	public HasValue<String> getPassword() {
		return passwordTb;
	}

	public HasValue<String> getPasswordRe() {
		return passwordReTb;
	}

	public HasText getRegisterHint() {
		return registerHint;
	}
	
	public HasKeyPressHandlers getKeyPressHandler() {
		return passwordReTb;
	}
	
}